package com.bwie.list.controller;

import com.bwie.common.domain.po.Goods;
import com.bwie.common.domain.vo.GoodsVo;
import com.bwie.common.result.Result;
import com.bwie.list.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/list")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 查询商品表
     * @return
     */
    @PostMapping("/findListAll")
    public Result<List<Goods>> findListAll(){
        List<Goods> result = goodsService.findListAll();
        return Result.success(result);
    }


    /**
     * 模糊查查询商品表
     * @return
     */
    @PostMapping("/findList")
    public Result<List<Goods>> findList(@RequestParam String goodsName){
        List<Goods> result = goodsService.findList(goodsName);
        return Result.success(result);
    }




    /**
     * 添加
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody GoodsVo goods){
        goodsService.add(goods);
        return Result.success();
    }

    /**
     * 图片上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result upload(@PathVariable MultipartFile file){
        Result result =  goodsService.upload(file);
        return Result.success(result);
    }

    /**
     * 下架
     * @param goodsId
     * @param goodsStatus
     * @return
     */
    @GetMapping("/updateup")
    public Result updateup(@RequestParam Integer goodsId,@RequestParam Integer goodsStatus){
        goodsService.updateup(goodsId,goodsStatus);
        return Result.success();
    }

    /**
     * 上架
     * @param goodsId
     * @param goodsStatus
     * @return
     */
    @GetMapping("/updateset")
    public Result updateset(@RequestParam Integer goodsId,@RequestParam Integer goodsStatus){
        goodsService.updateset(goodsId,goodsStatus);
        return Result.success();
    }
}
